import QtQuick 2.11
//import QtQuick.Controls 1.4
import QtQuick.Controls 2.2

import ".."
import "../_Global"
import "../_Global/Button"

import "../_Global/Global.js" as GlobalJS
import "../GameJS.js" as GameJS

Item {
    signal s_CreateGroup(int maxPlayerCount, string password, int classID)
    signal s_JoinGroup(int gID, string pass)
    signal s_Close()
    signal showConfig()

    //width: 600
    //height: 400
    id: root
    anchors.fill: parent

    Rectangle {
        id: background
        anchors.fill: parent

        Image { //背景
            id: backImage
            source: Global._FixResourcePath_R("Media/Images/Grades/Back.png")
            anchors.fill: parent
        }

        ImageButton2 {  //设置
            x: Global.dpW(1820)
            y: Global.dpH(0)
            width: Global.dpW(100)
            height: Global.dpH(100)
            source: Global._FixResourcePath_R("Media/Images/Exit/Config.png")
            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn
            onButtonClicked: {
                showConfig();
            }
        }

        ImageButton2 {
            id: buttonReturn
            x: Global.dpW(875)
            y: Global.dpH(915)
            width: Global.dpW(156)
            height: Global.dpH(122)
            source: Global._FixResourcePath_R("Media/Images/Return.png")

            soundEffectClick: Global.resource.effects.effectButton
            bEffectOn: Global.config.bEffectOn

            onButtonClicked: {
                s_Close();
            }
        }
/*
        ImageButton2 {
            id: buttonBeiJing
            x: Global.dpW(810)
            y: Global.dpH(110)
            width: Global.dpW(300)
            height: Global.dpH(100)
            source: Global._FixResourcePath_R("Media/Images/GameServers/BeiJing.png")

            onButtonClicked: {
                s_CreateGroup();
            }
        }

        ImageButton2 {
            id: buttonFuDan
            x: Global.dpW(810)
            y: Global.dpH(260)
            width: Global.dpW(300)
            height: Global.dpH(100)
            source: Global._FixResourcePath_R("Media/Images/GameServers/FuDan.png")

            onButtonClicked: {
                s_ExitGroup();
            }
        }
        */

        ColorButton {
            id: buttonCreate
            x: Global.dpW(310)
            y: Global.dpH(110)
            width: Global.dpW(300)
            height: Global.dpH(100)

            Text {
                font.pixelSize: Global.dpH(24)
                text: qsTr("创建房间")
                anchors.fill: parent
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
            onButtonClicked: {
                if(!isNaN(textPlayerCount.text)) {
                    if(textPlayerCount.text >= 2 && textPlayerCount.text <= 8)
                        s_CreateGroup(textPlayerCount.text, textPassWord.text, textClassID.text);
                }
            }
        }


        ColorButton {
            id: buttonJoin
            x: Global.dpW(610)
            y: Global.dpH(110)
            width: Global.dpW(300)
            height: Global.dpH(100)

            Text {
                font.pixelSize: Global.dpH(24)
                text: qsTr("随机加入房间")
                anchors.fill: parent
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
            onButtonClicked: {
                s_JoinGroup(0,"");
            }
        }

        ColorButton {
            id: buttonStart
            x: Global.dpW(910)
            y: Global.dpH(110)
            width: Global.dpW(300)
            height: Global.dpH(100)
            Text {
                font.pixelSize: Global.dpH(24)
                text: qsTr("进入房间")
                anchors.fill: parent
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
            }
            onButtonClicked: {
                if(!isNaN(textGroupID.text))
                    s_JoinGroup(textGroupID.text, textPassWord.text);
            }
        }
        TextField {
            id: textGroupID
            x: Global.dpW(1210)
            y: Global.dpH(110)
            width: Global.dpW(300)
            height: Global.dpH(100)
            selectByMouse: true
            placeholderText: "房间号"
        }


        TextField {
            id: textClassID
            x: Global.dpW(610)
            y: Global.dpH(210)
            width: Global.dpW(300)
            height: Global.dpH(100)
            selectByMouse: true
            placeholderText: "课程号"
            text: "0"
        }

        TextField {
            id: textPlayerCount
            x: Global.dpW(910)
            y: Global.dpH(210)
            width: Global.dpW(300)
            height: Global.dpH(100)
            selectByMouse: true
            placeholderText: "玩家数"
            text: "2"
        }

        TextField {
            id: textPassWord
            x: Global.dpW(1210)
            y: Global.dpH(210)
            width: Global.dpW(300)
            height: Global.dpH(100)
            selectByMouse: true
            placeholderText: "房间密码"
        }
    }



    Component.onCompleted: {
    }

}
